
// 登入接口请求
import axios from 'axios'
import { ElLoading } from 'element-plus'

// 设置动画——开始
let loading = ''
const startloading = () => {
    const option = {
        text: '亲,稍等片刻...',
        lock: 'true',
        background: 'rgba(0,0,0,0.7)'
    }
    loading = ElLoading.service(option)
}

const endLoading = () => {
    loading.close()
}
// 设置动画——结束
const loginaxios = axios.create({})
// 请求拦截
loginaxios.interceptors.request.use(res => {
    startloading()
    if (localStorage.elementToken) {
        res.headers.Authorizaion = localStorage.elementToken//如果有token 就将token添加的请求头一并发送
    }
    return res
})

// 响应拦截
loginaxios.interceptors.response.use(response => {
    endLoading()
    return response
}, error => {
    endLoading()
    return Promise.reject(error)
})

export default loginaxios